<template>
	<div>
		<!--查询部分-->
		<el-row>
			<el-col :span="3">
				<span>评分项目</span>
			</el-col>
			<el-col :span="10" style="margin-left: 20px;align:right">

				<el-button size="small" type="primary" @click="addButton">新 增</el-button>

				<el-button size="small" type="primary" @click="editButton">编 辑</el-button>

				<el-button size="small" type="primary" @click="startButton">启 用</el-button>

				<el-button size="small" type="primary" @click="stopButton">停 用</el-button>
			</el-col>
			<el-col :span="11">
			</el-col>
		</el-row>
		<el-row>
			<el-col :span="3">
				<el-table :data="tableDataTree.dataList" border @cell-click="queryButton" highlight-current-row>
					<el-table-column prop="itemName" label="项目名称" width="220"></el-table-column>
				</el-table>
			</el-col>

			<el-col :span="10" style="padding-left: 20px;">
				<el-table :data="tableData.dataList" stripe border @selection-change="handleSelectionChange">
					<el-table-column type="selection" width="50" fixed>
					</el-table-column>
					<el-table-column prop="itemName" label="项目名称" :formatter="itemCov"></el-table-column>
					<el-table-column prop="start" label="评分值"></el-table-column>
					<el-table-column prop="score" label="得分"></el-table-column>
					<el-table-column label="状态" :formatter="statusCov"></el-table-column>
				</el-table>
				<el-pagination small @size-change="handleSizeChange" @current-change="handleCurrentChange1" :current-page="CurentPage1" :page-sizes="page.pageSizes" :page-size="page.pageSize" layout=" total,prev, pager, next" :total="tableData.total"></el-pagination>

			</el-col>
			<el-col :span="11" style="padding-left:20px">
				<div>
					<span style="color:red">
						会员级别：0 无，1 普卡 2 银卡 3 金卡<br> 是否延保：1 是 0 否<br> 是否本店承保：1 是 0 否<br>
					</span>
					<span style="color:red">
						是否储值：0 无，1 自店 2 俱乐部
					</span>
				</div>
			</el-col>
		</el-row>

		<el-dialog title="新增" v-model="addDialogShow" size="tiny">

			<el-form :model="editData" :rules="rules" ref="editData" label-width="100px" class="demo-ruleForm">
				<el-form-item label="项目名称" prop="itemId">
					<el-select size="small" v-model="editData.itemId" placeholder="请选择" disabled>
						<el-option v-for="item in ItemNameCombo" :label="item.label" :value="item.value">
						</el-option>
					</el-select>
				</el-form-item>

				<el-form-item label="评分值" prop="start" required>

					<el-input v-model="editData.start" type="number" :min="0" size="small" placeholder="起始值"></el-input>
				</el-form-item>

				<el-form-item label="得分" prop="score" required>
					<el-input v-model="editData.score" type="number" size="small" :min="0" placeholder="得分"></el-input>
				</el-form-item>

			</el-form>

			<el-row>
				<el-col :span="12">
					<el-button type="primary" size="small" style="margin-left: 100px;" @click="addSubmit">提 交</el-button>
				</el-col>
				<el-col :span="12">
					<el-button type="primary" size="small" style="margin-left: 70px;" @click="addCansel">取 消</el-button>
				</el-col>
			</el-row>
		</el-dialog>

	</div>
</template>

<script>
export default {
	data: function() {
		return {
			// 规则
			rules: {
				itemId: [
					{ required: true, message: '请输入项目名称', trigger: 'blur' }

				],

			},
			CurentPage1: 1,
			//临时变量
			rowId: "",
			// 评级类型下拉
			scoreTypeCombo: [{
				label: "得分",
				value: "1",
			}, {
				label: "项目",
				value: "2",
			}],
			// 项目名称下拉
			ItemNameCombo: [],
			ItemNameConv: {},
			// 新增dialog显示
			addDialogShow: false,
			//  编辑dialog 显示
			// 查询集合
			queryData: {
				numberName: "",
			},
			CurentPageMj: 1,
			page: this.page,
			// 查询数据
			tableData: {
				total: 0,
				dataList: [],
			},
			// 左侧数查询数据
			tableDataTree: {
				total: 0,
				dataList: [],
			},
			// 修改数据
			editData: {

				start: 0, // 评级开始值
				stop: "", // 评级结束值
				countType: "", // 评分方式
				itemId: "", // 项目id
				score: 0, // 得分
				id: "",
				status: "1",
				dispOrder: "",

			},
			// 修改数据初始化
			emptyEditData: {
				start: 0, // 评级开始值
				stop: "", // 评级结束值
				countType: "", // 评分方式
				itemId: "", // 项目id
				score: 0, // 得分
				id: "",
				status: "1",
				dispOrder: "",

			},
			// 选择数据
			multipleSelection: "",
		}
	},
	methods: {
		//分页
		handleCurrentChange1: function(curr) {
			this.$data.CurentPage1 = curr;
			this.queryMethod(this.$data.rowId);
		},
		/*setCurrent:function(row) {
			this.$refs.singleTable.setCurrentRow(row);
			},*/
		//选择框
		handleSelectionChange: function(val) {
			debugger;
			this.$data.multipleSelection = val;
		},
		// 查 询
		queryButton: function(row) {
			debugger;
			this.$data.rowId = row.itemCode;
			this.queryMethod(row.itemCode); // http查询

		},
		// http查询方法封装
		queryMethod: function(id) {
			this.$data.tableData.dataList = [];
			//this.$data.tableData.total = 0;
			debugger;
			this.$http.get(this.API_ROOT + '/bc/custome/itemscore/list', {
				params: {
					id: id,
					start: this.$data.CurentPage1,
					limit: this.$data.page.pageSize,
				}
			}).then(resp => {
				debugger;
				if (resp.data.success) {
					resp.data.total = parseInt(resp.data.total);
					this.$data.tableData.dataList = resp.data.dataList;
					this.$data.tableData.total = resp.data.total;
				} else {
					this.$message.error(resp.data.msg);
				}
			}, resp => {
			});
		},
		// 左侧树查 询
		queryButton2: function() {
			debugger;
			this.$http.get(this.API_ROOT + '/bc/custome/itemscore/leftTree', {
				params: {
				}
			}).then(resp => {
				if (resp.data.success) {
					resp.data.total = parseInt(resp.data.total);
					this.$data.tableDataTree.dataList = resp.data.dataList;
					this.$data.tableDataTree.total = resp.data.total;
				} else {
					this.$message.error(resp.data.msg);
				}
			}, resp => {
			});
		},
		// 添加按钮
		addButton: function() {
			if (this.$data.rowId == "") {
				this.$message.warning("请点击左侧项目");
				return;
			}
			this.$data.editData = Object.assign(this.$data.editData, this.$data.emptyEditData);
			this.$data.editData.itemId = this.$data.rowId;
			this.$data.addDialogShow = true;
		},

		/**编辑按钮**/
		editButton: function() {
			debugger;
			if (this.$data.multipleSelection.length != 1) {
				this.$message.error("请选择一条数据");
				return;
			}
			this.$data.editData = Object.assign(this.$data.editData, this.$data.emptyEditData); //置空表单

			this.$http.get(this.API_ROOT + '/bc/custome/itemscore/info', {
				params: {
					id: this.$data.multipleSelection[0].id,
				}
			}).then(resp => {
				if (resp.data.success) {
					debugger;
					Object.assign(this.$data.editData, resp.data.data);
				} else {
				}
			}, resp => {
			});
			this.$data.addDialogShow = true;
		},
		// 启用
		startButton: function() {
			debugger;
			var tempId = this.$data.rowId;
			//alert("启用");
			if (this.$data.multipleSelection.length != 1) {
				this.$message.error("请选择一条数据");
				return;
			}
			this.$http.get(this.API_ROOT + '/bc/custome/itemscore/start', {
				params: {
					id: this.$data.multipleSelection[0].id,
				}
			}).then(resp => {
				if (resp.data.success) {
					this.$message(resp.data.msg);
					this.queryMethod(tempId); // 刷新
					this.$data.multipleSelection = []; // 选择置空
				} else {
					this.$message.error(resp.data.msg);
					this.queryMethod(tempId); // 刷新
					this.$data.multipleSelection = []; // 选择置空
				}
			}, resp => {
			});
		},
		// 停用
		stopButton: function() {
			debugger;
			var tempId = this.$data.rowId;
			//alert("停用");
			if (this.$data.multipleSelection.length != 1) {
				this.$message.error("请选择一条数据");
				return;
			}
			this.$http.get(this.API_ROOT + '/bc/custome/itemscore/stop', {
				params: {
					id: this.$data.multipleSelection[0].id,
				}
			}).then(resp => {
				if (resp.data.success) {
					this.$message(resp.data.msg);
					this.queryMethod(tempId); // 刷新
					this.$data.multipleSelection = []; // 选择置空
				} else {
					this.$message.error(resp.data.msg);
					this.queryMethod(tempId); // 刷新
					this.$data.multipleSelection = []; // 选择置空
				}
			}, resp => {
			});
		},
		/**【添加】提交**/
		addSubmit: function() {
			this.$refs.editData.validate((valid) => {
				if (valid) {

					this.$http.post(this.API_ROOT + '/bc/custome/itemscore/save', this.$data.editData, {
						params: {
						}
					}).then(resp => {
						if (resp.data.success) {
							this.$data.addDialogShow = false;
							this.$message.info("保存成功！");
							this.queryMethod(this.$data.rowId);
						} else {
							this.$message.error(resp.data.msg);
						}
					}, resp => {
					});

				} else {
					this.$message.error("表单填写不全！");
					return false;
				}
			});

		},
		/**【添加】取消**/
		addCansel: function() {
			debugger;
			this.$data.addDialogShow = false;
		},

		/**【编辑】 取消**/
		editCansel: function() {
			debugger;
			this.$data.addDialogShow = false;
		},

		//列表分页大小切换
		handleSizeChange: function() { },
		//列表当前页切换
		handleCurrentChange: function(currentPage) {

			debugger;
			this.$data.CurentPageMj = currentPage;
			this.queryMethod(this.$data.rowId);
		},

		// 状态转换
		statusCov: function(row) {
			switch (row.status) {
				case '0':
					return "未启用";
					break;
				case '1':
					return "已启用";
					break;

			}
		},
		// 状态转换
		itemCov: function(row) {
			return this.$data.ItemNameConv[row.itemId];
		},
		// 等级下拉
		levelCombo: function() {
			this.$http.get(this.API_ROOT + '/bc/custome/item/combo', {
				params: {

				}
			}).then(resp => {
				debugger;
				this.$data.ItemNameCombo = resp.data;
			}, resp => {
			});
			this.$http.get(this.API_ROOT + '/bc/custome/item/convert', {
				params: {

				}
			}).then(resp => {
				debugger;
				this.$data.ItemNameConv = resp.data;
			}, resp => {
			});

		},
		// 评级值转换
		countValueCov: function(row) {
			debugger;
			if (row.start == "" || row.start == null) {
				if (row.stop == "" || row.stop == null) {
					return "";
				}
				else {
					return row.stop;
				}
			}
			else {
				if (row.stop == "" || row.stop == null) {
					return row.start;
				}
				else {
					return row.start + " , " + row.stop;
				}
			}
		},
		// 编辑获取选中信息
		getDataById: function() {
			debugger;

		},
		// 评级类型转换
		scoreTypeCov: function(row) {
			switch (row.scoreType) {
				case "1":
					return "得分";
					break;
				case "2":
					return "项目";
					break;
				default:
					return "未知";
					break;
			}

		},
		//评级方式转换
		countTypeCov: function(row) {
			switch (row.countType) {
				case "zqj":
					return "在区间";
					break;
				case "qt":
					return "其它";
					break;
				default:
					return "未知";
					break;
			}
		},
		scoreItemCov: function(row) {

		}
	},
	created: function() {
		this.levelCombo(); // 获取下拉
		this.queryButton2(); // 获取编辑信息
	}
}
</script>

<style>

</style>